﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TankBattle.Models
{
    public class MultiSprite
    {
        private List<Sprite> sprites;
        private List<Vector2> spritesPosition;
        private bool loop;

        public MultiSprite(bool loop)
        {
            this.loop = loop;
            sprites = new List<Sprite>();
            spritesPosition = new List<Vector2>();
        }
        public void AddSprite(Sprite sprite, Vector2 spritePosition )
        {
            sprites.Add(sprite);
            spritesPosition.Add(spritePosition);
        }
        public void Update(int i)
        {
            sprites[i].Update();
        }
        public void Draw(SpriteBatch spriteBatch, int i)
        {
            sprites[i].Draw(spriteBatch, spritesPosition[i]);
        }
        public bool Update()
        {
            bool complete = true;
            for (int i = 0; i < sprites.Count; i++)
            {
                complete = false;
                if (sprites[i].Update())
                {
                    if (!loop)
                    {
                        sprites.RemoveAt(i);
                        spritesPosition.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        complete = true;
                    }
                }
            }
            return complete;
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < sprites.Count; i++)
            {
                sprites[i].Draw(spriteBatch, spritesPosition[i]);
                
            }
        }
        public void Draw(SpriteBatch spriteBatch, Vector2 position)
        {
            for (int i = 0; i < sprites.Count; i++)
            {
                sprites[i].Draw(spriteBatch, position);
            }
        }
        public int COUNT
        {
            get { return sprites.Count; }
        }
        public List<Vector2> Positions
        {
            get
            {
                return spritesPosition;
            }
        }
        public void SetPosition(int i, Vector2 position)
        {
            spritesPosition[i] = position;
        }
        public void Clear()
        {
            spritesPosition.Clear();
            sprites.Clear();
        }
    }
}
